<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="robots" content="index, follow"/>
<meta name="description" content="Tutorials, ideas for craft works using Coconut shells and experiences."/>
<meta name="keywords" content="Tutorials, ideas for craft works using Coconut shells and experiences."/>
<title>Index | Craft and talk</title>
<?php
include 'head.php';
?>
</head>
<body>
<?php
include 'nav.php';
?>
<div id="wrapper">
<div id="content">
		<div id="categories"></div>
		<div id="list">
		<?php
		include 'connect.php';
		mysql_select_db($db, $con);
		
		$query  = "SELECT * FROM {$table} ORDER BY ID DESC";
		$result = mysql_query($query) or die(mysql_error());
		$op = "";
		
		while($row = mysql_fetch_assoc($result)) {
			$url = $row['URL']."_id_".$row['ID'];
			
			$op = $op. "\n<a href='" . $url. "' class={$row['Category']}"."><div class='mainentry'>"
				 ."<h3>".$row['Name']."</h3>"
				 .$row['Date']." | <em class = 'cat'>".$row['Category']."</em></div></a>\n";
		}
		echo $op;
		mysql_close($con);
		?>
		</div>
</div>
</div>
<?php
include 'footer.php';
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
Array.prototype.unique = function() {    var o = {}, i, l = this.length, r = [];    for(i=0; i<l;i+=1) o[this[i]] = this[i];    for(i in o) r.push(o[i]);    return r;};
var allCats = document.getElementsByClassName('cat');
var cats = [];
for(var i = 0; i < allCats.length; i++){
	cats[i] = allCats[i].innerHTML;
}
cats = cats.unique();
var whereToPut = document.getElementById('categories');
op = "<strong>Filter by: </strong><a href='#' onclick='showAll()'>All</a> ";
for(i = 0; i < cats.length; i++){
	op += ('<a href="#" onclick="toggle(this.innerHTML)">' + cats[i] + '</a> ');
}
whereToPut.innerHTML += op;


function toggle(what){
	//var str = '".' + what + '"';
	$('#list a').show().not("."+what).hide();
}

function showAll(){
	$('#list a').show();
}


</script>
</body>
</html>